<?php
include_once '../include/lxbase.class.php';
$webconn = new Lxbase();
$host = 'http://'.$_SERVER["HTTP_HOST"].'/';
$u=$_GET["u"];
$t=$_GET["t"];
$url=urldecode($_GET["url"]); if(!empty($u)){
	$wxinfo = $webconn->viewdata("*","wxuser","where userid={$u}");
}elseif(!empty($t)){
	$u = $webconn->oncedata("id","users","where token='{$t}'");
	
	if(empty($u)){
		die('没有用户信息');
	}
	$wxinfo = $webconn->viewdata("*","wxuser","where userid={$u}");
}else{
	die("参数不全");
}
$temparr = array('content'=>$url);
$ret = $webconn->mongo()->insert('wxtemp',$temparr,true);
$mid=$temparr["_id"]->{'$id'};
$data["u"]=$u;
$data["mid"]=$mid;
$state=base64_encode(json_encode($data));
$url='https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$wxinfo["appid"].'&redirect_uri='.$host.'api/apicallback.php&response_type=code&scope=snsapi_userinfo&state='.$state.'#wechat_redirect';
header("location:".$url);
exit;